<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原生Js获取焦点</title>
    <style>
        .demo{
            background-color: lightblue;
        }
    </style>
</head>
<body>
    <button id="btn">点我给页面加一个输入框</button>
    <script>
        const btn = document.getElementById('btn')
        btn.onclick = ()=>{
            const input = document.createElement('input')
            document.body.appendChild(input)
            input.className = 'demo'
            input.focus()
        }
    </script>
</body>
</html>